<script>
/**
 * @param {string} path
 * @returns {Boolean}
 */
function isExternal(path) {
    return /^(https?:|mailto:|tel:)/.test(path)
}
export default {
    props: {
        to: {
            type: [String, Object],
            default: "/",
        },
        target: {
            type: String,
            default: "",
        },
    },
    render(creteElement) {
        if (isExternal(this.to)) {
            return creteElement(
                "a",
                {
                    attrs: {
                        href: this.to,
                        target: this.target || "_blank",
                    },
                },
                this.$slots.default
            )
        }
        return creteElement(
            "router-link",
            {
                class: ["mmv-router-link"],
                attrs: {
                    to: this.to,
                    target: this.target,
                },
            },
            this.$slots.default
        )
    },
}
</script>
